package cn.brondfish.icedfish.framework.util;
import android.content.Context;
import android.os.Build;
import android.provider.Settings.Secure;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class BF_DeviceUniqueID {

    public static String generateUniqueID(Context context) {
        String source = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID)
                + Build.BRAND + Build.MODEL + Build.ID + Build.VERSION.INCREMENTAL;
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hash = digest.digest(source.getBytes());
            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) hexString.append('0');
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e){
            return String.valueOf(source.hashCode());
        }
    }
}
